package leecode;

import java.text.MessageFormat;
import java.util.Arrays;

/**
 *
 *
 * @author qingyan 2021-07-08
 */
public class Question88 {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        /*Arrays.sort(nums1);
        Arrays.sort(nums2);*/
        int p1 = m - 1;
        int p2 = n - 1;
        int p = nums1.length - 1;
        while (p2 >= 0) {
            if (nums1[p1] >= nums2[p2]) {
                nums1[p] = nums1[p1];
                p1--;
                p--;
            } else {
                nums1[p] = nums2[p2];
                p2--;
                p--;
            }
        }

    }

    public static void main(String[] args) {
        Question88 q88 = new Question88();
        int[] num1 = {1, 2, 3, 0, 0, 0};
        int[] num2 = {2, 5, 6};
        q88.merge(num1, 3, num2, 3);
        System.out.println(Arrays.toString(num1));
    }
}
